<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>



        const url = 'http://www.liulongbin.top:3006/api/jsonp';

        // jsonp请求函数
        function req (conf) {
            const script = document.createElement('script');
            window.success = function (res) {
                script.remove();
                conf.success && conf.success(res);
            };
            script.setAttribute('src', `${conf.url}?callback=success&${Object.keys(conf.params).map(k => `${k}=${conf.params[k]}`).join('&')}`);
            // 发送请求
            document.body.appendChild(script);
        }

        setInterval(() => {
            req({
                url,
                params: {
                    name: 'zs',
                    age: 18,
                },
                success (res) {
                    console.log(res);
                },
            });
        }, 2000);


    </script>

</body>
</html>